﻿using API_Service;
using API_Service.BizLogic.BasicData;
using API_Service.BizLogic.Bom;
using Nancy;
using System;
using System.Collections.Generic;
using System.Web;

namespace API_Service.Module
{
    public class BomModule: BaseAPIModule
    {
        private BomService bomService = new BomService();

        public BomModule(): base("/bomdata")
        {
            Get["/"] = _ => Response.AsJson("基础资料维护");

            #region 供应商数据服务API
            
            //VV
            Get["/bom/{bomno}"] = p =>
            {
                string bomno = (string)p.bomno;

                return Response.AsJson(bomService.GetBomDataByBomno(bomno));
            };
            //VV
            Post["/bomalternative/get"] = _ =>
            {
                string model = Request.Form["MODEL"];

                return Response.AsJson(bomService.GetBomAlternaviveDataByPartNo(model));
            };

            //VV
            Post["/bom/add"] = _ =>
            {
                string model = Request.Form["MODEL"];

                return Response.AsJson(bomService.AddBomPartNo(model));
            };

            //VV
            Post["/bom/delete"] = _ =>
            {
                string model = Request.Form["MODEL"];

                return Response.AsJson(bomService.DeleteBomPartNo(model));
            };

            //VV
            Post["/bom/update"] = _ =>
            {
                string model = Request.Form["MODEL"];

                return Response.AsJson(bomService.UpdateBomByPartNo(model));
            };

            //VV
            Post["/bomalternative/add"] = _ =>
            {
                string model = Request.Form["MODEL"];

                return Response.AsJson(bomService.AddBomAlternativePartNo(model));                
            };

            //VV
            Post["/bomalternative/update"] = _ =>
            {
                string model = Request.Form["MODEL"];

                return Response.AsJson(bomService.UpdateBomAlternativeByPartNo(model));
            };

            Post["/bomalternative/delete"] = _ =>
            {
                string model = Request.Form["MODEL"];

                return Response.AsJson(bomService.DeleteBomAlternativePartNo(model));
            };
            #endregion

            Get["/partcode"] = _ =>
            {
                return Response.AsJson(bomService.GetPartModeList());
            };

            Get["/bomlist"] = _ =>
            {
                return Response.AsJson(bomService.GetBOMList());
            };

        }

    }
}